package huaweiod.third;

import java.util.*;

public class B_MessageLoop {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        Map<Integer, Set<Integer>> map = new HashMap<>();
        for (int i = 0; i < count; i++) {
            int send = in.nextInt();
            int receive = in.nextInt();
            map.putIfAbsent(send, new HashSet<>());
            map.putIfAbsent(receive, new HashSet<>());
            map.get(send).add(receive);
        }

        System.out.println(process(map));
    }

    private static boolean process(Map<Integer, Set<Integer>> map) {
        for (Integer send : map.keySet()) {
            for (Integer receive : map.get(send)) {
                Set<Integer> receiveSet = map.get(receive);
                if (!receiveSet.contains(send)) {
                    return false;
                }
            }
        }
        return true;
    }
}
